<template>
	<div class="main"> 
		<div class="outerDiv">
			<headerBack>
				<b class="my-center" slot="my-center">优势科目测评</b>
			</headerBack>
			<scroller style="top: 0.88rem;">
				<div class="main-box">
					<div>
						<CardLineStep rightTitle="学习成绩" :hasWrite="step1" :circleTip="step1 ? '√' : '1'" :isCircleFinish="step1"
						 :isTopLineFinish="step > 0" :isBottomLineFinish="step > 1" :nextStep="2" :finishStep="step" :isStart="isStart" :orderNum="1"></CardLineStep>
						<CardLineStep rightTitle="学习兴趣" :hasWrite="step2" :circleTip="step2? '√' : '2'" :isCircleFinish="step2"
						 :isTopLineFinish="step > 1" :isBottomLineFinish="step > 2" :nextStep="3" :finishStep="step"></CardLineStep>					
						<CardLineStep rightTitle="师资水平测试" :hasWrite="step3" :circleTip="step3 ? '√' : '3'" :isCircleFinish="step3"
						 :isTopLineFinish="step > 2" :isBottomLineFinish="step > 3" :nextStep="4" :finishStep="step"></CardLineStep>					
						<CardLineStep rightTitle="对老师好感度" :hasWrite="step4" :circleTip="step4 ? '√' : '4'" :isCircleFinish="step4"
						 :isTopLineFinish="step > 3" :isBottomLineFinish="step > 4" :nextStep="5" :finishStep="step"></CardLineStep>
						<CardLineStep rightTitle="老师推荐科目" :hasWrite="step5" :circleTip="step5 ? '√' : '5'" :isCircleFinish="step5"
						 :isTopLineFinish="step > 4" :isBottomLineFinish="step > 5" :nextStep="6" :finishStep="step"></CardLineStep>
							<CardLineStep rightTitle="家长推荐科目" :hasWrite="step6" :circleTip="step6 ? '√' : '6'" :isCircleFinish="step6"
						 :isTopLineFinish="step > 5" :isBottomLineFinish="step > 6" :nextStep="7" :finishStep="step"></CardLineStep>
						 <CardLineStep rightTitle="同学排除科目" :hasWrite="step7" :circleTip="step7 ? '√' : '7'" :isTopLineFinish="step > 6"
						 :isBottomLineFinish="step > 7" :isCircleFinish="step7" :nextStep="8" :finishStep="step" :isEnd="isEnd"></CardLineStep>
					</div>
					<div style="width: 7.5rem;height: 5rem;"></div>
				</div>
			</scroller>
			<div class="footer">
				<div class="top">
					<div class="top_1">
						<b>测试完成</b>
						<span class="num"><b>{{lens}}</b>/7</span>
					</div>
					<div class="top_2">
						<!-- 生成剩余次数: {{sxkCount}} -->
					</div>
				</div>
				<div class="bottom">
					<button class="btn watchResult" @click="commonJs.gopush('chooseRecds')">查看综合测试排序结果</button>
					<button :class="['btn','createNew',lens<7?'cre1':'cre2']" @click="sunCase">生成新的综合测试排序</button>
					
				</div>
			</div>
		</div>
	</div>
</template>
 
<script>
	import CardLineStep from '~/components/CardLineStep'
	import {Toast} from 'vux'
	import headerBack from "~/components/headerBack";
	import Header from '~/components/Header'
	import { getAdvantageUsage, getEvaluation, createReport, getChooseProvince} from "~/api/selectCourse"
	import ls from 'store2'
	export default {
		components: {
			CardLineStep,
			Header,
			headerBack,
			Toast
		},
		data() {
			return {
				isEnd: true,
				isStart: true,
				step: 3,
				step1: '',
				step2: '',
				step3: '',
				step4: '',
				step5: '',
				step6: '',
				step7: '',
				dolist: [],
				lens: 0,
				ids: '',
				isSix:true
			}
		},
		mounted: function() {

			this.$visit(this.$route.path)
			this.getEvaluation()	
			this.getChooseProvince()
		},

		methods: {
			sunCase() {
				//  测试分类 1、学习成绩测试 2、学习兴趣测试  3、师资水平测试 4、对老师好感度 5、老师推荐科目 6、家长推荐科目 7、同学排除科目
				if (this.lens < 7) {
					return false;
				}			
				let A = JSON.parse(this.step1) //1、学习成绩测试			
				let B = JSON.parse(this.step2) //2、学习兴趣测试
				let C = JSON.parse(this.step3) //3、师资水平测试
				let D = JSON.parse(this.step4) //4、对老师好感度
				let E = JSON.parse(this.step5) //5、老师推荐科目
				let F = JSON.parse(this.step6) //6、家长推荐科目
				let G = JSON.parse(this.step7) //7、同学排除科目	
				let dili = 5 * A.rate1 + 2.5*B.rate1+1.5*C.rate1+D.rate1+E.rate1+F.rate1-G.rate1
				let lishi = 5 * A.rate2 + 2.5*B.rate2+1.5*C.rate2+D.rate2+E.rate2+F.rate2-G.rate2;
				let zhenzhi = 5 * A.rate3 + 2.5*B.rate3+1.5*C.rate3+D.rate3+E.rate3+F.rate3-G.rate3;
				let wuli = 5 * A.rate4 + 2.5*B.rate4+1.5*C.rate4+D.rate4+E.rate4+F.rate4-G.rate4;
				let huaxue = 5 * A.rate5 + 2.5*B.rate5+1.5*C.rate5+D.rate5+E.rate5+F.rate5-G.rate5;
				let senwu = 5 * A.rate6 + 2.5*B.rate6+1.5*C.rate6+D.rate6+E.rate6+F.rate6-G.rate6;
				let jishu = 5 * A.rate7 + 2.5*B.rate7+1.5*C.rate7+D.rate7+E.rate7+F.rate7-G.rate7;
				var datas = {}
				if(this.isSix){
					datas = {					
					"地理": {
						"num": dili
					},
					"历史": {
						"num": lishi
					},
					"政治": {
						"num": zhenzhi
					},
					"物理": {
						"num": wuli
					},
					"化学": {
						"num": huaxue
					},
					"生物": {
						"num": senwu
					}					
				}
				}else{
					datas = {					
					"地理": {
						"num": dili
					},
					"历史": {
						"num": lishi
					},
					"政治": {
						"num": zhenzhi
					},
					"物理": {
						"num": wuli
					},
					"化学": {
						"num": huaxue
					},
					"生物": {
						"num": senwu
					},
					"技术": {
						"num": jishu
					}
				}
				}
				
				this.createReport(JSON.stringify(datas))
			},
			getChooseProvince(){
				getChooseProvince(ls.get('userArea')).then(res => {
					if(res.data==="3+3(7选3)"){
						this.isSix = 0
					}else{
						this.isSix = 1
					}
			
					sessionStorage.setItem('chooseSubject',this.isSix)
				}).catch(()=>{

				})
			},
			getEvaluation() {
				this.$loading('open')
				getEvaluation(ls.get('userType')).then(res => {
					if (res.code === '0') {
						this.step1 = res.data.score;
						this.step2 = res.data.interest;
						this.step3 = res.data.standard;
						this.step4 = res.data.favorability;
						this.step5 = res.data.method;
						this.step6 = res.data.patriarch;
						this.step7= res.data.schoolmate;
						this.ids = res.data.id;
						if (this.step1) {
							this.lens += 1
						}
						if (this.step2) {
							this.lens += 1
						}
						if (this.step3) {
							this.lens += 1
						}
						if (this.step4) {
							this.lens += 1
						}
						if (this.step5) {
							this.lens += 1
						}
						if (this.step6) {
							this.lens += 1
						}
						if (this.step7) {
							this.lens += 1
						}
						this.$hideLoading()
					}
				}).catch(() => {
					this.$hideLoading()
				})
			},
	
			createReport(data) {
				let obj = {
					generate: 3,
					ranking: data,
					id: this.ids
				}
				createReport(obj).then(res => {
					if (res.code === '0') {
						this.$vux.toast.text(res.message);
						setTimeout(() => {
							this.commonJs.gopush('chooseRecds')
						}, 50)
					}
				}).catch(() => {
					this.$vux.toast.text(res.message);
				})
			},

		}
	}
</script>

<style lang="less" scoped>


	.outerDiv {
		width: 100%;
		height: 100vh;
		background: #fff;
		position: relative;

		.title {
			padding: 0 0.3rem;
			margin-bottom: 0.4rem;
			font-size: 0.44rem;
			font-weight: bold;
		}

		.footer {
			width: 7.5rem;
			height: 2rem;
			background: #fff;
			box-shadow: 0px -4px 10px 0px rgba(204, 204, 204, 0.2);
			padding: 0 0.3rem;
			position: fixed;
			bottom: 0;
			left: 0;

			.top {
				height: 1rem;
				padding-right: 0.68rem;
				color: #BBBBBB;
				display: flex;
				justify-content: space-between;
				align-items: center;

				.top_1 {
					font-size: 0.26rem;

					b {
						color: #222;
						font-weight: bold;
					}

					.num {
						margin-left: 0.2rem;

						b {
							color:@mainColor;
							font-size: 0.4rem;
							margin-right: 0.07rem;
						}
					}
				}

				.top_2 {
					font-size: 0.26rem;
					font-weight: bold;
					color: rgba(187, 187, 187, 1);

				}
			}

			.bottom {
				display: flex;
				justify-content: space-between;

				.btn {
	
					outline: none;
					font-size: 0.22rem;
					font-weight: bold;
					border-radius: 10px;
					border: none;
					width: 4rem;
					height: 0.8rem;
					background: @mainColor;
					border-radius: 0.4rem;
					margin: 0 auto;
				}

				.createNew {
					color: #fff;

				}

				.cre1 {
					background: #EEE;
				}

				.cre2 {
					background:@mainColor;
				}

				.watchResult {
					background:@mainColor;				
					color: #fff;
					margin-right: 0.2rem;
				}
			}
		}
	}
	.main-box{
		margin-top: 0.25rem;
	}
	.my-center{
		font-weight: 600;
	}
</style>
